package com.star.spring.ai.function;

import com.star.spring.ai.service.NewsService;

import java.io.IOException;
import java.util.function.Function;

public class HotNewsFunction implements Function<HotNewsFunction.Request, HotNewsFunction.Response> {

    public record Request(String day) {
    }

    /**
     * Weather Function response.
     */
    public record Response(String news) {
    }

    @Override
    public HotNewsFunction.Response apply(HotNewsFunction.Request request) {
        String news = "";
        NewsService newsService = new NewsService();
        try {
            news = newsService.getHotNews().toString();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return new HotNewsFunction.Response(news);
    }

}